package com.ruoyi.core.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.core.domain.ClientProduct;
import com.ruoyi.core.domain.custombean.BatchActivationCodeSummaryListQueryResult;
import com.ruoyi.core.service.IBatchActivationCodeSummaryService;
import com.ruoyi.core.vo.BatchActivationCodeSummaryCreateOperationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * batch_coreController
 *
 * @author ruoyi
 * @date 2020-09-28
 */
@Api("激活码批量信息管理")
@RestController
@RequestMapping("/batch-activation-code-summaries")
public class BatchActivationCodeSummaryController extends BaseController {
    @Autowired
    private IBatchActivationCodeSummaryService batchActivationCodeSummaryService;

    /**
     * 查询batch_core列表
     */
    @ApiOperation("激活码批量信息列表")
    @PreAuthorize("@ss.hasRole('admin')")
    @GetMapping
    public TableDataInfo list() {
        startPage();
        List<BatchActivationCodeSummaryListQueryResult> list = batchActivationCodeSummaryService.findAll();
        return getDataTable(list);
    }

    /**
     * 查询batch_core列表
     */
    @ApiOperation("激活码权限明细")
    @PreAuthorize("@ss.hasRole('admin')")
    @GetMapping("/{batchId}/products")
    public AjaxResult getProductByBatchId(@PathVariable("batchId") Long batchId) {
        List<ClientProduct> list = batchActivationCodeSummaryService.findClientProductByBatchId(batchId);
        return AjaxResult.success(list);
    }

//    /**
//     * 导出batch_core列表
//     */
//    @PreAuthorize("@ss.hasPermi('batch-activation-code-summary:export')")
//    @Log(title = "batch_core", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(BatchActivationCodeSummary batchActivationCodeRecord) {
//        List<BatchActivationCodeSummary> list = batchActivationCodeSummaryService.selectBatchActivationCodeRecordList(batchActivationCodeRecord);
//        ExcelUtil<BatchActivationCodeSummary> util = new ExcelUtil<BatchActivationCodeSummary>(BatchActivationCodeSummary.class);
//        return util.exportExcel(list, "batch-activation-code-summary");
//    }

//    /**
    //     * 获取batch_core详细信息
    //     */
    //    @PreAuthorize("@ss.hasPermi('batch-activation-code-summary:query')")
    //    @GetMapping(value = "/{id}")
    //    public AjaxResult getInfo(@PathVariable("id") Long id) {
    //        return AjaxResult.success(batchActivationCodeSummaryService.selectBatchActivationCodeRecordById(id));
    //    }

    /**
     * 新增batch_core
     */
    @Log(title = "激活码批量管理", businessType = BusinessType.INSERT)
    @ApiOperation("激活码批量创建")
    @PreAuthorize("@ss.hasRole('admin')")
    @PostMapping
    public AjaxResult createBatchActivationCodeSummary(@RequestBody BatchActivationCodeSummaryCreateOperationVo BatchActivationCodeSummaryCreateVo) {
        return toAjax(batchActivationCodeSummaryService.createBatchActivationCodeSummary(BatchActivationCodeSummaryCreateVo));
    }

//    /**
//     * 修改batch_core
//     */
//    @ApiOperation("批量激活码激活&冻结操作")
//    @PreAuthorize("@ss.hasRole('admin')")
//    @PutMapping
//    public AjaxResult edit(@RequestBody BatchActivationCodeSummary batchActivationCodeRecord) {
//        return toAjax(batchActivationCodeSummaryService.updateBatchActivationCodeRecord(batchActivationCodeRecord));
//    }

    /**
     * 删除batch_core
     */
    @Log(title = "激活码批量管理", businessType = BusinessType.DELETE)
    @ApiOperation("激活码批量删除")
    @PreAuthorize("@ss.hasRole('admin')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return AjaxResult.success(batchActivationCodeSummaryService.deleteBatchActivationCodeRecordByIds(ids));
    }



}
